package com.example.homework2.Interface;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.homework2.R;

import java.util.ArrayList;
import java.util.List;

public class UC3 extends AppCompatActivity {

    ImageView change_image1, change_image2, change_image3, change_image4, change_image5;
    ImageView last_image;
    Button back;

    List<ImageView> pic = new ArrayList<>();
    int i = 0;

    private class UC3_Thread extends Thread {
        @Override
        public void run() {
            while (true) {
                try {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            pic.get(i).setVisibility(View.VISIBLE);
                            if (last_image != null) {
                                last_image.setVisibility(View.GONE);
                            }
                            last_image = pic.get(i);
                            if (i == 4) {
                                i = 0;
                            }
                            else {
                                i += 1;
                            }
                        }
                    });
                    Thread.sleep(1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);

        change_image1 = findViewById(R.id.change_image1);
        change_image2 = findViewById(R.id.change_image2);
        change_image3 = findViewById(R.id.change_image3);
        change_image4 = findViewById(R.id.change_image4);
        change_image5 = findViewById(R.id.change_image5);
        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        pic.add(change_image1);
        pic.add(change_image2);
        pic.add(change_image3);
        pic.add(change_image4);
        pic.add(change_image5);

        UC3_Thread uc3Thread = new UC3_Thread();
        uc3Thread.start();

    }
}